package com.example.demo1.aspect;
import com.example.demo1.VO.R;
import com.example.demo1.core.RUtil;
import com.example.demo1.exception.REnum;
import com.example.demo1.exception.RException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if (e instanceof RException){
            RException rException = (RException) e;
            return RUtil.error(rException.getCode(),rException.getMessage());
        }
        return RUtil.error(REnum.UNKOWN_ERR);
    }
}



